	.file "calcfloat.s"
	.text
	.global CalcFloatDemo
	.type CalcFloatDemo, @function
CalcFloatDemo:
	pushq	%rbp
	movq	%rsp, %rbp

	movl	%esi, %r11d
	movss	(%rdi), %xmm0	#max
	movss	%xmm0, %xmm1	#min
	movss	%xmm0, %xmm2	#sum

	movl	$0, %r10d
	decl	%r11d
1:
	incl	%r10d
	cmpl	%r11d, %r10d
	jg	Done

	addq	$4, %rdi
	comiss	(%rdi), %xmm0
	ja	FindMin
	movss	(%rdi), %xmm0
	jmp	CalcSum
FindMin:
	comiss	(%rdi), %xmm1
	jb	CalcSum
	movss	(%rdi), %xmm1
CalcSum:
	addss	(%rdi), %xmm2
	jmp 1b

Done:
	cvtsi2ss	%esi, %xmm3
	movss	%xmm0, (%rdx)
	movss	%xmm1, (%rcx)
	movss	%xmm2, (%r8)
	divss	%xmm3, %xmm2
	movss	%xmm2, (%r9)

	leaveq
	retq
